package org.sam.swing;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * 可以折叠的panel，看一下能不能实现要的效果
 * 
 * @author sam
 *
 */
public class JPanelCollect extends JPanel implements Collect {

	private static final long serialVersionUID = -4388156119991165190L;

	/**
	 * 是否点选中
	 */
	private boolean ibClick = false;

	/**
	 * 折叠
	 */
	@Override
	public void doCollect() {
		this.setSize(0, 0);
	}

	/**
	 * 取消折叠
	 */
	@Override
	public void unCollect() {
		this.setSize(320, 640);
	}

	public JPanelCollect() {
		this.setLayout(new BorderLayout());
		JButton btn = new JButton("点我");
		this.add(btn, BorderLayout.CENTER);
		
		btn.addActionListener( e -> {
			if (ibClick){
				this.doCollect();
			} else {
				this.unCollect();
			}
			ibClick = !ibClick;
		});
	}
}
